package website.digitalocean.chapter14;

/**
 * @Author: 582895699@qq.com
 * @Desctription:
 * @Date: Created in 2023/2/13 22:17
 */
public class Dollar50Dispenser implements DispenseChain {

    private DispenseChain chain;

    @Override
    public void sendNextChain(DispenseChain dispenseChain) {
        this.chain = dispenseChain;
    }

    @Override
    public void dispense(Currency cur) {
        int amount = cur.getAmount();
        if (amount >= 50) {
            int num = cur.getAmount() / 50;
            int remainder = amount % 50;
            System.out.println("Dispensing " + num + " 50$ note");
            if (remainder != 0) {
                this.chain.dispense(new Currency(remainder));
            } else {
                this.chain.dispense(cur);
            }
        }
    }

}